<?php
namespace App\Models;

use App\Models\Simple\XMLModel;

/*
 * Mock travel destination data.
 * Note that we don't have to extend CodeIgniter's model for now
 */

class Players extends XMLModel
{
    protected $origin = WRITEPATH . 'data/playersdata.xml';
    protected $keyField = 'id';
    protected $validationRules = [];
    public function update($id, array $data)
    {
        // Check if the record exists
        if (!isset($this->data[$id])) {
            return false;
        }

        // Update each field with new data
        foreach ($data as $field => $value) {
            if (property_exists($this->data[$id], $field)) {
                $this->data[$id]->$field = (string)$value;
            }
        }

        // Save changes back to the XML file
        return $this->store();
    }

    /**


     * Load the collection state from an XML document.
     */
    protected function load()
    {
        parent::load();
    }

    /**
     * Store the collection state as an XML document.
     */
    protected function store()
    {
        return parent::store();
    }
}